package com.example.demo.study.io;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

// 文件操作
public class FileTest {
    public static void main(String[] args) throws IOException {
        // 文件操作 -- 先创建
//        File file = new File("D:/productMe/file/test.txt");
//        System.out.println(file.exists());

        // 文件写入内容
        FileWriter fileWriter = new FileWriter("D:/productMe/file/test.txt");
        fileWriter.write("这个是测试内容卫栖梧厅地城椅");
        fileWriter.close();
        // 文件读出内容
        File file = new File("D:/productMe/file/test.txt");
        Scanner scanner = new Scanner(file);
        String content = "";
        while (scanner.hasNextLine()){
            content = scanner.nextLine();
//            System.out.println(scanner.nextLine());
        }
        scanner.close();
        System.out.println("本次测试内容："+content);

    }
}
